package com.amap.client;

import com.alibaba.fastjson2.JSONObject;
import com.amap.builder.AmapParamBuilder;
import com.amap.config.AmapMerchantConfig;
import com.amap.http.impl.AmapRestTemplateHttpClient;
import com.amap.sign.impl.RSA2SignStrategy;
import com.amap.template.AmapClientTemplate;
import org.springframework.stereotype.Service;

/**
 * 商家调用高德
 * @author liuyi
 * @since 2025/10/31 9:15
 */
@Service
public class AmapMerchantSdkClient {
    private final AmapClientTemplate clientTemplate;

    public AmapMerchantSdkClient() {
        this.clientTemplate = null;
    }

    public AmapMerchantSdkClient(AmapMerchantConfig config) {
        this.clientTemplate = new AmapClientTemplate(config, new RSA2SignStrategy(), new AmapRestTemplateHttpClient());
    }

    public JSONObject getAmapResult(Object obj, String method) {
        AmapParamBuilder paramBuilder = (new AmapParamBuilder()).method(method).putBeanToBizParam(obj);
        return this.clientTemplate.execute(paramBuilder);
    }
}
